package com.jdqzyy.noobnoob.common.activeController;

import com.jdqzyy.noobnoob.common.resultVO.NoobResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.xml.ws.http.HTTPException;
import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author Zyy
 * @Description:全局的异常处理
 * @date 2020/11/21下午9:29
 * @slogan 天下风云出我辈，一入代码岁月催
 */
@RestControllerAdvice(basePackages = "com.jdqzyy.noobnoob")
public class ExceptionController {
    /**
     * 全局异常捕捉处理
     * @param exception
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public NoobResult errorHandler(Exception exception) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        exception.printStackTrace(pw);
        String details = sw.toString();
        return NoobResult.error().msg(details);
    }
}
